const admin_model = require('../db/admin_model')

// 查询证书
const get_all_users = async (ctx) => {
    try {
      const users = await admin_model.get_user_select()
      ctx.body = users
    } catch (error) {
      ctx.throw(400, error)
    }
  }

const post_user_select = async (ctx, next) => {
    const {stu_name} = ctx.request.body
    try {
      const user = await admin_model.user_select_name(stu_name)
      ctx.body = user
    } catch (error) {
      ctx.throw(400, error)
    }
  }

const get_all_class = async (ctx) => {
    try {
      const classRoom = await admin_model.get_classRoom_select()
      ctx.body = classRoom
    } catch (error) {
      ctx.throw(400, error)
    }
  }
  const get_all_class_all = async (ctx) => {
    try {
      const classRoom = await admin_model.get_classRoom_select_all()
      ctx.body = classRoom
    } catch (error) {
      ctx.throw(400, error)
    }
  }
  
  const get_classRoom_apply = async (ctx) => {
    try {
      const classRooms = await admin_model.get_classRoom_select_apply()
      ctx.body = classRooms
    } catch (error) {
      ctx.throw(400, error)
    }
  }

  // 
  const delete_ClassRoom =  async (ctx) => {
    const {id} = ctx.request.body
    try {
      const classroom = await admin_model.classroom_delete_by_id(id)
      ctx.body = classroom
    } catch (error) {
      ctx.throw(400, error)
    }
  }
  
// 获取用户信息条数
const select_num_user_ = async(ctx) => {
  try{
    const number_user = await admin_model.select_user_number()
    ctx.body = number_user
  }catch{
    ctx.throw(400,error)
  }
}

const select_apply_N = async(ctx) => {
  try{
    const apply_n = await admin_model.get_apply_select_N()
    ctx.body = apply_n
  }catch{
    ctx.throw(400,error)
  }
}


const updata_classroom = async (ctx) => {
  const classroom = {id,class_name,class_type,class_other} = ctx.request.body
  try {
    const result = await admin_model.upload_classroom(classroom)
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}
const get_classroom1 = async (ctx) => {
  try {
    const result = await admin_model.selsct_classroom_Y()
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}
const get_classroom2 = async (ctx) => {
  try {
    const result = await admin_model.selsct_classroom_N()
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}

const SET_classroom__ =  async (ctx) => {
  const apply_class = {id,class_start} = ctx.request.body
  try {
    const result = await admin_model.SET_classroom_y(apply_class)
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}
const get_apply_all_Y = async (ctx) => {
  try {
    const result = await admin_model.selsct_apply_Y()
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}
const get_apply_all_N = async (ctx) => {
  try {
    const result = await admin_model.selsct_apply_N()
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}

const set_spply_NT =  async (ctx) => {
  const apply_id = {id} = ctx.request.body
  try {
    const result = await admin_model.SET_apply_NT(apply_id)
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}

const set_spply_Y =  async (ctx) => {
  const apply_id = {id} = ctx.request.body
  try {
    const result = await admin_model.SET_apply_Y(apply_id)
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}
const GET_Apply_Y =  async (ctx) => {
  try {
    const result = await admin_model.get_apply_NT()
    ctx.body = result
  } catch (error) {
    ctx.throw(400, error)
  }
}


module.exports = {
    get_all_users,
    post_user_select,
    get_all_class,
    get_all_class_all,
    get_classRoom_apply,
    delete_ClassRoom,
    select_num_user_,
    select_apply_N,
    updata_classroom,
    get_classroom2,
    get_classroom1,
    SET_classroom__,
    get_apply_all_N,
    get_apply_all_Y,
    set_spply_NT,
    set_spply_Y,
    GET_Apply_Y
}